package com.example.snowinfo;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseObject;

public class Drugi_aktiviti extends Activity {

	RatingBar mbar;
	TextView tv,tv1;
	Button ba;
	String ava,b,test;
	private static final String url = "jdbc:mysql://studsrv.uni-mb.si:3306/e1059081";

	private static final String user = "E1059081";

	private static final String pass = "E1059081";
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Parse.initialize(this, "WICUVR6szrnwHaJjyaC35qGmdSBWFcNNGM89nF5D", "rUmhuKA2ShyZz0MSIgWCgTgW3S1mIEhYmp5gZXu1");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_drugi_aktiviti);
		tv=(TextView) findViewById(R.id.textView1);
		tv1=(TextView) findViewById(R.id.textView2);
		Intent i=getIntent();
		b=i.getStringExtra("Proga");
		tv1.setText(b);
		mbar=(RatingBar) findViewById(R.id.ratingBar1);	
	/*	ba=(Button) findViewById(R.id.button1);
		ba.setOnClickListener(new OnClickListener(){
		    public void onClick(View v) {


		    	float[] i=new float[] {mbar.getRating()};

		        tv.setText("value is " + i[0]);
		    }
		});*/
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.drugi_aktiviti, menu);
		return true;
	}
	public void klik(View view){
		//float i = ((RatingBar)layout.findViewById(R.id.ratingBar1)).getRating();
		//float[] i=new float[] {mbar.getRating()};
		   //tv.setText("Ocena:" + i[0]);
		   insertData();
	}
	public void insertData(){
		float[] i=new float[] {mbar.getRating()};
		ParseObject testObject = new ParseObject("TestObject");
		testObject.put(b,i[0]);
		testObject.saveInBackground();
		tv.setText("Ocena:" + i[0]);
		try{
			Class.forName("com.mysql.jdbc.Driver");
		Connection con = DriverManager.getConnection("jdbc:mysql://studsrv.uni-mb.si:3306/e1059081",user,pass);
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("insert into smucisce values '"+2+"','"+i+"' ");
		while(rs.next()) {
		ava=rs.getString(0);
		}
		}
		catch(Exception exc){
		System.out.println("SQLException: " + exc.getMessage());
		}
	 
		//tv.setText(ava);//textVirew
		


	}

}
